require 'rubygems'
require 'hpricot'
require 'open-uri'

def fetch_meeting_page(page_url)
  puts "Fetching #{page_url}"
  doc = Hpricot(open(page_url))
  # look for PDF links on the meeting page
  links = doc.search('//a')
  links.each do |link|
      puts link.inner_html if (link['href'] =~ /pdf/ and link.inner_html =~ /Agenda/)
    #puts link.inner_html if link['href'] =~ /pdf/
    puts link.inner_html if link['inner_html'] =~ /Agenda/ #and link['href'] =~ /pdf/
  end
end

doc = Hpricot(open("#{MCC_SITE_SCRIPTS_URL}/meetings_committees.php?headerID=12"))

list = doc.search("//ul[@class='list']/li")

list.each do |entry|
  link = entry.at('a') # <a> inside the <li>
  href = link['href']
  fetch_meeting_page(href)
  text = link.inner_text
  date = Date.parse(text)
end
